import requests
import json

'''

'''


class CreateApi:

    def __init__(self):
        pass

    def create(self, token, appId, packageMd5, name):
        headers = {
            "User-Agent": "RestSharp/107.3.0.0",
            "Accept": "application/json, text/json, text/x-json, text/javascript, application/xml, text/xml",
            "Content-Type": "application/json; charset=utf-8",
            "sign": "grUONqSUuf1HTEBisoQfzg1vcLIKGjqRoTuZb3oZxcU=",
            "Xybot-Client-RequestId": "a649b6cd-6ba1-4bfc-8a94-b1a3049483bf",
            "timezone": "%2b08%3a00",
            "ipv4": "192.168.43.133",
            "Accept-Language": "zh-CN,zh;q=1",
            "Authorization": f"bearer {token}"
        }
        url = "https://api.winrobot360.com/api/client/app/develop/create"
        data = {
            "Xybot-Client-RequestId": "a649b6cd-6ba1-4bfc-8a94-b1a3049483bf",
            "appId": appId,
            "appPackage": {
                "activities": None,
                "appFlowParamList": [],
                "appIcon": "",
                "appType": "app",
                "customItems": {
                    "gifUrl": None,
                    "imageName": "",
                    "imageUrl": "",
                    "uiaType": "pc",
                    "videoUrl": ""
                },
                "description": "",
                "elementLibraryCodes": [],
                "enableViewSource": False,
                "externalDependencies": [],
                "instruction": "",
                "internalDependencies": [],
                "ipaasDependencies": [],
                "name": name,
                "packageCode": "",
                "statistics": {
                    "blockCount": 2,
                    "flowCount": 1,
                    "magicBlockCount": 0,
                    "sourceLineCount": 0
                },
                "terminalTags": "",
                "uiTags": None,
                "uiaType": "pc",
                "videoUrl": ""
            },
            "elementLibraryStatus": 0,
            "groupId": "",
            # packageMd5 用第二次请求的 AssignUploadUrl 返回的值
            "packageMd5": packageMd5
        }
        data = json.dumps(data, separators=(',', ':'))
        response = requests.post(url, headers=headers, data=data)

        print(f"create_api Status Code: {response.status_code}")
        print(f"create_api Response Text: {response.text}")


if __name__ == '__main__':
    CreateApi().create()
